package b3.widget.home.operation
{
	import b3.model.*;
	import b3.net.*;
	import b3.scene.home.grid.BuildingGrid;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class OperationPane extends BasicWidget
	{
		public static const REMOVE:int = 0;
		public static const ATTACK:int = 1;
		public static const ASSIST:int = 2;
		public static const REBUILD:int = 3;
		public static const INFO:int = 4;
		
		public static const TOP:int = 0;
		public static const RIGHT:int = 1;
		public static const BOTTOM:int = 2;
		public static const LEFT:int = 3;
		
		private var buildingModel:BuildingModel;
		private var clickCount:int;
		
		public function OperationPane(buildingModel:BuildingModel)
		{
			this.buildingModel = buildingModel;
			//背景圆圈
			var OperationPaneBgr:Class = ResourceHelper.getInstance().getClassByName("OperationPaneBgr");
			addChild(new OperationPaneBgr());
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			clickCount = 0;
			stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);
		}
		
		private function onStageMouseClick(event:Event):void
		{
			if (clickCount-- < 0)
				close();
		}
		
		public function addOperation(type:int, position:int):void
		{
			var operationClass:Array = [OperationRemove, OperationAttack, OperationAssist, OperationRebuild, OperationScanInfo];
			//上右下左的具体相对位置数组
			var posX:Array = [85, 150, 85, 15];
			var posY:Array = [25, 85, 140, 85];
			var operationIcon:BasicIcon = new operationClass[type](buildingModel);
			operationIcon.x = posX[position] - operationIcon.width / 2;
			operationIcon.y = posY[position] - operationIcon.height / 2;
			addChild(operationIcon);
		}
		
	}
}